import { useState, useEffect } from 'react';
import { getWithdrawPermission, getIsUrge } from '../commonServices';

export const useUrgeAndWithDraw = (props: { processId: any; instanceId: any; tabKey: any; isNewVersionDesigner: boolean; }) => {
  const { processId, instanceId, tabKey, isNewVersionDesigner } = props;
  const [showWithdraw, $showWithdraw] = useState(false);
  const [showIsUrge, $showIsUrge] = useState(false);

  useEffect(() => {
    if (!isNewVersionDesigner) {
      if (tabKey == '3' || tabKey == '6') {
        const params = {
          processDefinitionId: '',
          processInstanceId: '',
        };
        params.processDefinitionId = processId;
        params.processInstanceId = instanceId;
        getWithdrawPermission(params).then((res) => {
          $showWithdraw(res);
        });

        getIsUrge(params).then((res) => {
          $showIsUrge(res);
        });
      }
    }
  }, [processId, instanceId, tabKey, isNewVersionDesigner]);

  return {
    showIsUrge,
    showWithdraw,
  };
};
